/*  Common structs and types defined for the HTTP protocol API */
#ifndef _HTTPCLIENT_DEF_H_
#define _HTTPCLIENT_DEF_H_

#include "ohos_types.h"

#ifdef __cplusplus
extern "C" {
#endif

#define  UINT32  uint32

typedef  unsigned long UINTP;

/* Global default sizes */
#define HTTPCLIENT_MAX_URL_LENGTH 1024 /* Maximum length for an HTTP Url parameter*/

/* HTTP Session flags (Public flags) */
#define HTTPCLIENT_FLAG_KEEP_ALIVE         0x00000001 /* Set the keep alive header */
#define HTTPCLIENT_FLAG_SEND_CHUNKED       0x00000002 /* The outgoing should chunked */
#define HTTPCLIENT_FLAG_NO_CACHE           0x00000004 /* Set the no cache header */
#define HTTPCLIENT_FLAG_ASYNC              0x00000008 /* Currently not implemented */

/* HTTP status internal flags */
#define HTTPCLIENT_STATE_PRE_INIT          0x00000000  /* Starting stage */
#define HTTPCLIENT_STATE_INIT              0x00000001  /* API was initialized (memory was allocated) */
#define HTTPCLIENT_STATE_URL_PARSED        0x00000002  /* Url was parsed */
#define HTTPCLIENT_STATE_HOST_CONNECTED    0x00000004  /* HEAD verb was sent */
#define HTTPCLIENT_STATE_HEAD_SENT         0x00000008  /* Post verb was sent */
#define HTTPCLIENT_STATE_POST_SENT         0x00000010  /* HTTP requet was sent */
#define HTTPCLIENT_STATE_REQUEST_SENT      0x00000020  /* HTTP request was sent */
#define HTTPCLIENT_STATE_HEADERS_RECIVED   0x00000040  /* Headers ware recived from the server */
#define HTTPCLIENT_STATE_HEADERS_PARSED    0x00000080  /* HTTP headers ware parsed */
#define HTTPCLIENT_STATE_HEADERS_OK        0x00000100  /* Headers  status was OK */

#if 0
/* HTTP Error code */
#define HTTPCLIENT_SUCCESS                  0 /* HTTP Success status */
#define HTTPCLIENT_UNKNOWN_ERROR            1 /* Unknown error */
#define HTTPCLIENT_ERROR_INVALID_HANDLE     2 /* an Invalid handle or possible bad pointer was passed to a function */
#define HTTPCLIENT_ERROR_NO_MEMORY          3 /* Buffer too small or a failure while in memory allocation */
#define HTTPCLIENT_ERROR_SOCKET_INVALID     4 /* an attempt to use an invalid socket handle was made */
#define HTTPCLIENT_ERROR_SOCKET_RESOLVE     6 /* Error while resolving host name */
#define HTTPCLIENT_ERROR_SOCKET_CANT_SET    5 /* Can't send socket parameters */
#define HTTPCLIENT_ERROR_SOCKET_CONNECT     7 /* Error while connecting to the remote server */
#define HTTPCLIENT_ERROR_SOCKET_TIME_OUT    8 /* socket time out error */
#define HTTPCLIENT_ERROR_SOCKET_RECV        9 /* Error while receiving data */
#define HTTPCLIENT_ERROR_SOCKET_SEND       10 /* Error while sending data */
#define HTTPCLIENT_ERROR_HEADER_RECV       11 /* Error while receiving the remote HTTP headers */
#define HTTPCLIENT_ERROR_HEADER_NOT_FOUND  12 /* Could not find element within header */
#define HTTPCLIENT_ERROR_HEADER_BIG_CLUE   13 /* The headers search clue was too large for the internal API buffer */
#define HTTPCLIENT_ERROR_HEADER_NO_LENGTH  14 /* No content length was specified for the outgoing data. the caller should specify chunking mode in the session creation */
#define HTTPCLIENT_ERROR_CHUNK_TOO_BIG     15 /* The HTTP chunk token that was received from the server was too big and possibly wrong */
#define HTTPCLIENT_ERROR_AUTH_HOST         16 /* Could not authenticate with the remote host */
#define HTTPCLIENT_ERROR_AUTH_PROXY        17 /* Could not authenticate with the remote proxy */
#define HTTPCLIENT_ERROR_BAD_VERB          18 /* Bad or not supported HTTP verb was passed to a function */
#define HTTPCLIENT_ERROR_LONG_INPUT        19 /* a function received a parameter that was too large */
#define HTTPCLIENT_ERROR_BAD_STATE         20 /* The session state prevents the current function from proceeding */
#define HTTPCLIENT_ERROR_CHUNK             21 /* Could not parse the chunk length while in chunked transfer */
#define HTTPCLIENT_ERROR_BAD_URL           22 /* Could not parse curtail elements from the URL (such as the host name, HTTP prefix act') */
#define HTTPCLIENT_ERROR_BAD_HEADER        23 /* Could not detect key elements in the received headers */
#define HTTPCLIENT_ERROR_BUFFER_RSIZE      24 /* Error while attempting to resize a buffer */
#define HTTPCLIENT_ERROR_BAD_AUTH          25 /* Authentication schema is not supported */
#define HTTPCLIENT_ERROR_AUTH_MISMATCH     26 /* The selected authentication schema does not match the server response */
#define HTTPCLIENT_ERROR_NO_DIGEST_TOKEN   27 /* an element was missing while parsing the digest authentication challenge */
#define HTTPCLIENT_ERROR_NO_DIGEST_ALG     28 /* Digest algorithem could be MD5 or MD5-sess other types are not supported */
#define HTTPCLIENT_ERROR_SOCKET_BIND       29 /* Binding error */
#define HTTPCLIENT_ERROR_TLS_NEGO          30 /* Tls negotiation error */
#define HTTPCLIENT_ERROR_NOT_IMPLEMENTED   64 /* Feature is not (yet) implemented */
#define HTTPCLIENT_EOS                   1000 /* HTTP end of stream message */
#endif

/** @brief   This enumeration defines the API return type.  */
typedef enum {
	HTTPCLIENT_SUCCESS                =    0, /**< HTTP Success status */
	HTTPCLIENT_UNKNOWN_ERROR		  =    1, /**< Unknown error */
	HTTPCLIENT_ERROR_INVALID_HANDLE   =    2, /**< an Invalid handle or possible bad pointer was passed to a function */
	HTTPCLIENT_ERROR_NO_MEMORY		  =    3, /**< Buffer too small or a failure while in memory allocation */
	HTTPCLIENT_ERROR_SOCKET_INVALID   =    4, /**< an attempt to use an invalid socket handle was made */
	HTTPCLIENT_ERROR_SOCKET_RESOLVE   =    6, /**< Error while resolving host name */
	HTTPCLIENT_ERROR_SOCKET_CANT_SET  =    5, /**< Can't send socket parameters */
	HTTPCLIENT_ERROR_SOCKET_CONNECT   =    7, /**< Error while connecting to the remote server */
	HTTPCLIENT_ERROR_SOCKET_TIME_OUT  =    8, /**< socket time out error */
	HTTPCLIENT_ERROR_SOCKET_RECV	  =    9, /**< Error while receiving data */
	HTTPCLIENT_ERROR_SOCKET_SEND	  =   10, /**< Error while sending data */
	HTTPCLIENT_ERROR_HEADER_RECV	  =   11, /**< Error while receiving the remote HTTP headers */
	HTTPCLIENT_ERROR_HEADER_NOT_FOUND =   12, /**< Could not find element within header */
	HTTPCLIENT_ERROR_HEADER_BIG_CLUE  =   13, /**< The headers search clue was too large for the internal API buffer */
	HTTPCLIENT_ERROR_HEADER_NO_LENGTH =   14, /**< No content length was specified for the outgoing data. the caller should specify chunking mode in the session creation */
	HTTPCLIENT_ERROR_CHUNK_TOO_BIG	  =   15, /**< The HTTP chunk token that was received from the server was too big and possibly wrong */
	HTTPCLIENT_ERROR_AUTH_HOST		  =   16, /**< Could not authenticate with the remote host */
	HTTPCLIENT_ERROR_AUTH_PROXY 	  =   17, /**< Could not authenticate with the remote proxy */
	HTTPCLIENT_ERROR_BAD_VERB		  =   18, /**< Bad or not supported HTTP verb was passed to a function */
	HTTPCLIENT_ERROR_LONG_INPUT 	  =   19, /**< a function received a parameter that was too large */
	HTTPCLIENT_ERROR_BAD_STATE		  =   20, /**< The session state prevents the current function from proceeding */
	HTTPCLIENT_ERROR_CHUNK			  =   21, /**< Could not parse the chunk length while in chunked transfer */
	HTTPCLIENT_ERROR_BAD_URL		  =   22, /**< Could not parse curtail elements from the URL (such as the host name, HTTP prefix act') */
	HTTPCLIENT_ERROR_BAD_HEADER 	  =   23, /**< Could not detect key elements in the received headers */
	HTTPCLIENT_ERROR_BUFFER_RSIZE	  =   24, /**< Error while attempting to resize a buffer */
	HTTPCLIENT_ERROR_BAD_AUTH		  =   25, /**< Authentication schema is not supported */
	HTTPCLIENT_ERROR_AUTH_MISMATCH	  =   26, /**< The selected authentication schema does not match the server response */
	HTTPCLIENT_ERROR_NO_DIGEST_TOKEN  =   27, /**< an element was missing while parsing the digest authentication challenge */
	HTTPCLIENT_ERROR_NO_DIGEST_ALG	  =   28, /**< Digest algorithem could be MD5 or MD5-sess other types are not supported */
	HTTPCLIENT_ERROR_SOCKET_BIND	  =   29, /**< Binding error */
	HTTPCLIENT_ERROR_TLS_NEGO		  =   30, /**< Tls negotiation error */
	HTTPCLIENT_ERROR_NOT_IMPLEMENTED  =   64, /**< Feature is not (yet) implemented */
	HTTPCLIENT_EOS					  = 1000, /**< HTTP end of stream message */
} HTTPCLIENT_RESULT;

/*HTTP API structures */
// HTTPClient Supported authentication methods
typedef enum _httpclientAuthSchema_e {
    HTTPCLIENT_AUTHSCHEMA_NONE = 0,
    HTTPCLIENT_AUTHSCHEMA_BASIC,
    HTTPCLIENT_AUTHSCHEMA_DIGEST,
    HTTPCLIENT_AUTHSCHEMA_KERBEROS,
    HTTPCLIENT_AUTHSCHEMA_BEARER,  /* 20180823 add for oauth2.0 token. */
    HTTPCLIENT_AUTHSCHEMA_NOSUPPORT
} httpclientAuthSchema_e;

/* HTTPClient supported verbs */
typedef enum _httpclientVerb_e {
    HTTPCLIENT_GET    = 0,
    HTTPCLIENT_POST,
    HTTPCLIENT_PUT,
    HTTPCLIENT_DELETE, /* Note: currently not supported */
    HTTPCLIENT_HEAD,
    HTTPCLIENT_NOSUPPORT
} httpclientVerb_e;

/* Data structure that the caller can request at any time that will include some information regarding the session */
typedef struct _httpclient_t {
    UINT32 HTTPStatusCode;                 /* HTTP Status code (200 OK)  */
    UINT32 RequestBodyLengthSent;          /* Total bytes sent (body only)  */
    UINT32 ResponseBodyLengthReceived;     /* Total bytes received (body only)  */
    UINT32 TotalResponseBodyLength;        /* as extracted from the �content-length" header  */
    UINT32 HttpState;
} httpclient_t;

#ifdef __cplusplus
}
#endif

#endif // _HTTPCLIENT_DEF_H_
